package cn.ucox.web.ms.exception;

import java.util.HashMap;

/**
 * 缓存操作异常
 *
 * @author chenw
 * @create 2017-03-02 14:14
 * @email javacspring@gmail.com
 */
public class CacheOperationException extends BasicException {

    private Action action;
    private String key;
    private Object value;

    public CacheOperationException(Action action) {
        this(action, "缓存操作错误", null, null);
    }

    public CacheOperationException(Action action, String key) {
        this(action, "缓存操作错误", key, null);
    }

    public CacheOperationException(Action action, String key, Object value) {
        this(action, "缓存操作错误", key, value);
    }

    public CacheOperationException(Action action, String message, String key, Object value) {
        super(CODE_CACHE_OPERATION_EXCEPTION, message);
        this.action = action;
        this.key = key;
        this.value = value;
    }

    @Override
    public Object getData() {
        return new HashMap<String, Object>() {{
            put("action", action.value());
            put("key", key);
            put("value", value);
        }};
    }
}
